<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>$.ajax实现</title>
    <script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.js"></script>
    <script>
        function fun() {
           // 使用$.ajax()发送异步请求
        //    const formData = new FormData();
        //    formData.append("name", "Horace");
        //    formData.append("age", 20);
           $.ajax({
               url: 'http://localhost:1314', // 请求路径
               type: 'POST', // 请求方式(默认GET)
               data: JSON.stringify({
                   "name": "Horace",
                   "age": 20
               }),
               success: data => { // 响应成功回调
                  console.log(data);
               },
               error: () => {
                   alert("error!")
               }
           });
        }
    </script>
</head>

<body>
    <input type="button" value="发送异步请求" onclick="fun()">
</body>

</html>